package com.ymdx.action;

import com.opensymphony.xwork2.ActionSupport;
import com.ymdx.util.responseSupport.ResponseTool;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * Action类的基类，封装了request，response等
 * Created by yangliwei on 2017/8/13.
 */
public class GenericActionSupport extends ActionSupport implements Serializable, SessionAware, ServletRequestAware, ServletResponseAware {
    private static final long serialVersionUID = -36537673447612639L;
    protected final Logger log = LoggerFactory.getLogger(getClass());


    protected static final String ERROR = "error";
    protected static final String JSON = "json";
    protected static final String STREAM="stream";
    protected static final String REDIRECT = "redirect";


    protected Long id;
    protected Map<String, Object> session;
    protected HttpServletRequest request;
    protected HttpServletResponse response;
    protected Map<String, Object> responseMap = new HashMap<String, Object>();// 以键值对的形式返回
    protected ResponseTool responseTool = new ResponseTool();//封装了部分信息

    protected String errorMessage = "出错了，请联系管理员或者稍后重试";

    @Override
    public void setServletRequest(HttpServletRequest request) {
        this.request = request;
    }

    @Override
    public void setServletResponse(HttpServletResponse response) {
        this.response = response;
    }

    @Override
    public void setSession(Map<String, Object> session) {
        this.session = session;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Map<String, Object> getSession() {
        return session;
    }

    public HttpServletRequest getRequest() {
        return request;
    }

    public void setRequest(HttpServletRequest request) {
        this.request = request;
    }

    public HttpServletResponse getResponse() {
        return response;
    }

    public void setResponse(HttpServletResponse response) {
        this.response = response;
    }

    public Map<String, Object> getResponseMap() {
        return responseMap;
    }

    public void setResponseMap(Map<String, Object> responseMap) {
        this.responseMap = responseMap;
    }



    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    public ResponseTool getResponseTool() {
        return responseTool;
    }

    public void setResponseTool(ResponseTool responseTool) {
        this.responseTool = responseTool;
    }
}
